<?php
class WebUser extends CWebUser
{
	public function isStaff(){
		$arrRoles = Yii::app()->user->getState('roles');
		return (in_array('staffs', $arrRoles) || in_array('administrators', $arrRoles));
	}
	public function hasPermission($permissionName)
	{
		//check role first: always allow admin and denied members
		$arrRoles = Yii::app()->user->getState('roles');
		foreach($arrRoles as $id => $role){
			if(	$id == 1 && $role == 'administrators' ) return true;
			if( $id != 2 ) return false;
			/*TODO: LỖI NẾU USER THUỘC NHIỀU ROLE*/
		}
		
		//check permission
		$allowedPermissions = Yii::app()->user->getState('permissions');
		if(!empty($allowedPermissions) && in_array($permissionName, $allowedPermissions)){
			return true;	
		}
		return false;
	}
}